package com.guslegend.spzx.manager.demo;

import io.minio.BucketExistsArgs;
import io.minio.MakeBucketArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;

import java.io.FileInputStream;

/**
 * @author: guslegend
 * @description: Minio测试
 * @create: 2025-05-08 09:36
 **/
public class FileUploadTest {

    public static void main(String[] args) throws Exception{
        //创建一个Minio的客户端对象
        MinioClient minioClient=MinioClient.builder()
                .endpoint("http://192.168.150.131:9001")
                .credentials("admin","admin123456")
                .build();

        boolean found=minioClient.bucketExists(BucketExistsArgs.builder().bucket("spzx-bucket").build());

        //如果不存在,那么此时就创建一个新的桶
        if (!found){
            minioClient.makeBucket(MakeBucketArgs.builder().bucket("spzx-bucket").build());
        }else {
            //如果存在打印信息
            System.out.println("Bucket 'spzx-bucket' already exists.");
        }

        FileInputStream fis=new FileInputStream("D://01.jpg");
        PutObjectArgs putObjectArgs=PutObjectArgs.builder()
                .bucket("spzx-bucket")
                .stream(fis, fis.available(), -1)
                .object("01.jpg")
                .build();
        minioClient.putObject(putObjectArgs);

        //构建fileUrl
        String fileUrl="http://192.168.150.131:9001" ;
        System.out.println(fileUrl);
    }
}
